using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Acms.SqlDal;

namespace Acms.Bll
{
    public class PostTopic : BaseItem
    {
        private PostTopic() : base() { }
        private PostTopic(Hashtable table) : base(table) { }
        private PostTopic(Hashtable table, List<PostTopic> collection) : base(table, collection) { }

        protected override Base CreateDal()
        {
            return new PostTopicDal();
        }

        public static PostTopic CreateInstance()
        {
            return new PostTopic();
        }

        public static PostTopic CreateInstance(int postId, int topicId)
        {
            PostTopic tmp = new PostTopic();
            tmp.postId = postId;
            tmp.topicId = topicId;
            return tmp;
        }

        private static PostTopic Get(Hashtable table)
        {
            if (table != null)
                return new PostTopic(table);
            else
                return null;
        }

        private static List<PostTopic> Get(Hashtable[] tables)
        {
            if (tables != null)
            {
                List<PostTopic> tmp = new List<PostTopic>();
                foreach (Hashtable table in tables)
                {
                    tmp.Add(new PostTopic(table, tmp));
                }
                return tmp;
            }
            else
                return null;
        }

        public static List<PostTopic> GetAllByPostId(int postId)
        {
            PostTopicDal dal = new PostTopicDal();
            return Get(dal.GetAllByPostId(postId));
        }

        protected override void Load(Hashtable table)
        {
            postId = (int)table[PostTopicDal.Fields.PostId];
            postName = (string)table[PostTopicDal.Fields.PostName];
            postDisplayName = (string)table[PostTopicDal.Fields.PostDisplayName];
            topicId = (int)table[PostTopicDal.Fields.TopicId];
            topicName = (string)table[PostTopicDal.Fields.TopicName];
        }


        private int postId;
        public int PostId
        {
            get { return postId; }
        }

        private string postName;
        public string PostName
        {
            get { return postName; }
        }

        private string postDisplayName;
        public string PostDisplayName
        {
            get { return postDisplayName; }
        }

        private int topicId;
        public int TopicId
        {
            get { return topicId; }
        }

        private string topicName;
        public string TopicName
        {
            get { return topicName; }
        }

        protected override void DeleteRecord(object concurencyId, Base dal)
        {
            ((PostTopicDal)dal).Delete(postId, topicId, concurencyId);
        }

        protected override void SaveChanges(ref object concurencyId, Base dal)
        {
            ((PostTopicDal)dal).Update(postId, ref postName, ref postDisplayName, topicId, ref topicName, ref concurencyId);
        }

        public new void Update()
        {
            base.Update();
        }

        public new void Delete()
        {
            base.Delete();
        }

    }
}
